//package com.itheima.consumer.mq;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.ExchangeTypes;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.messaging.converter.MessageConversionException;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalTime;
//
//@Slf4j
//@Component
//public class SpringRabbitListener {
//
//
//   /* @RabbitListener(queues = "simple.queue")
//    public void ListenSimpleQueue(Message message) {
//        log.info("监听到simple.queue的消息 ID：【{}】", new String(message.getMessageProperties().getMessageId()));
//        log.info("监听到simple.queue的消息：【{}】", new String(message.getBody()));
////        throw new MessageConversionException("我是故意的！");
//    }*/
//    //验证不同消费者处理消费的能力，使用prefetch可以让消费者一次处理一个消息，当前消息没有处理完不能执行后续的处理
//    @RabbitListener(queues = "work.queue")
//    public void listenWorkQueue1(String msg) throws InterruptedException {
//        System.out.println("消费者1接收到消息：【" + msg + "】" + LocalTime.now());
//        Thread.sleep(20);
//    }
//
//    @RabbitListener(queues = "work.queue")
//    public void listenWorkQueue2(String msg) throws InterruptedException {
//        System.err.println("消费者2........接收到消息：【" + msg + "】" + LocalTime.now());
//        Thread.sleep(200);
//    }
//
//    /*@RabbitListener(queues = "fanout.queue1")
//    public void listenFanoutQueue1(String msg) {
//        System.out.println("消费者1接收到Fanout消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "fanout.queue2")
//    public void listenFanoutQueue2(String msg) {
//        System.out.println("消费者2接收到Fanout消息：【" + msg + "】");
//    }
//
//    //direct交换机
//    @RabbitListener(queues = "direct.queue1")
//    public void listenDirectQueue1(String msg) {
//        System.out.println("消费者1接收到direct.queue1的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "direct.queue2")
//    public void listenDirectQueue2(String msg) {
//        System.out.println("消费者2接收到direct.queue2的消息：【" + msg + "】");
//    }*/
//
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.queue3", durable = "true"),
//            exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
//            key = {"red", "blue"}
//    ))
//    public void listenerDirectQueue3(String msg) {
//        System.out.println("消费者3接收到direct.queue3的消息：【" + msg + "】");
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.queue4", durable = "true"),
//            exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
//            key = {"red", "yellow"}
//    ))
//    public void listenDirectQueue4(String msg){
//        System.out.println("消费者4接收到direct.queue4的消息：【" + msg + "】");
//    }
//}
